| Conditions | 2 | 
| Total Lines | 21 | 
| Code Lines | 19 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | import { useState } from "react"; | ||
| 2 | |||
| 3 | export default function PasswordGenerator() { | ||
| 4 | const [length, setLength] = useState(12); | ||
| 5 |   const [result, setResult] = useState(""); | ||
| 6 | |||
| 7 |   const generatePassword = () => { | ||
| 8 | const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%"; | ||
| 9 | let password = ""; | ||
| 10 |     for (let i = 0; i < length; i++) { | ||
| 11 | password += charset.charAt(Math.floor(Math.random() * charset.length)); | ||
| 12 | } | ||
| 13 | setResult(password); | ||
| 14 | }; | ||
| 15 | |||
| 16 | return ( | ||
| 17 | <div> | ||
| 18 | <h2>Password Generator</h2> | ||
| 19 |       <input type="number" value={length} onChange={(e) => setLength(Number(e.target.value))} min={4} max={50} /> | ||
| 20 |       <button onClick={generatePassword}>Generate</button> | ||
| 21 |       <input type="text" value={result} readOnly /> | ||
| 22 | </div> | ||
| 23 | ); | ||
| 24 | } |